<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>自动输入的动画效果</title>
</head>
<style>
#underLine {
    opacity: 1;
    animation: thunder 0.5s infinite;
}
@keyframes thunder {
      0% {
       opacity: 1;
      }

      50% {
        opacity: 0.5;
      }

      100% {
        opacity: 0;
      }
    }
</style>
<body>
    <div id="demo"></div>
    <script>
        function inputTextAuto(params) {
            let n = 1;
            const string = "hello world";
            const demo = document.querySelector('#demo');
            demo.innerHTML = string.substr(0,n) + '<span id="underLine">_</span>';
            let timer = setInterval(()=>{
                n+=1;
                demo.innerHTML=string.substr(0,n) + '<span id="underLine">_</span>';
                if(n === string.length) {
                    clearInterval(timer);
                    let underLine = document.querySelector('#underLine');
                    underLine.parentElement.removeChild(underLine);
                };
            },1000)
        }
        inputTextAuto();
     
    </script>
</body>
</html>